﻿Imports System.IO

Public Class SettingsViewModel
    Inherits ViewModelBase

    Public Sub New()
        'init to current settings
        DebugTools32bitPath = My.Settings.DbgTools_x86_FolderPath
        DebugTools64bitPath = My.Settings.DbgTools_x64_FolderPath
        SymbolPath = My.Settings.SymbolFolderPath
    End Sub

    Private mDebugTools32bitPath As String
    Public Property DebugTools32bitPath As String
        Get
            Return mDebugTools32bitPath
        End Get
        Set(ByVal value As String)
            mDebugTools32bitPath = value
            RaisePropertyChanged("DebugTools32bitPath")
        End Set
    End Property

    Private mDebugTools64bitPath As String
    Public Property DebugTools64bitPath As String
        Get
            Return mDebugTools64bitPath
        End Get
        Set(ByVal value As String)
            mDebugTools64bitPath = value
            RaisePropertyChanged("DebugTools64bitPath")
        End Set
    End Property

    Private mSymbolPath As String
    Public Property SymbolPath As String
        Get
            Return mSymbolPath
        End Get
        Set(ByVal value As String)
            mSymbolPath = value
            RaisePropertyChanged("SymbolPath")
        End Set
    End Property

    Public Sub Save()
        If Not ValidateSettings() Then Exit Sub
        My.Settings.SymbolFolderPath = SymbolPath
        My.Settings.DbgTools_x86_FolderPath = DebugTools32bitPath
        My.Settings.DbgTools_x64_FolderPath = DebugTools64bitPath
        My.Settings.Save()
    End Sub

    Private Function ValidateSettings() As Boolean
        Dim bld As New System.Text.StringBuilder
        Dim isValid As Boolean = True
        If Not Directory.Exists(SymbolPath) Then
            bld.AppendLine("Symbol path is not found")
            isValid = False
        End If
        If Not Directory.Exists(DebugTools32bitPath) Then
            bld.AppendLine("32bit Debug Tools path is not found")
            isValid = False
        End If
        If Not Directory.Exists(DebugTools64bitPath) Then
            bld.AppendLine("64bit Debug Tools path is not found")
            isValid = False
        End If
        If Not isValid Then MessageBox.Show(String.Format("Validation errors:{0}{1}", Environment.NewLine, bld.ToString))
        Return isValid
    End Function
End Class
